package cn.rongdao.jrkabao.util;

import android.content.Context;

import com.igexin.sdk.PushManager;
import com.mifengkong.frtools.http.util.CookieConstant;
import com.mifengkong.frtools.util.FRSharedPreferences;

import cn.rongdao.jrkabao.dao.UserDao;
import cn.rongdao.jrkabao.ui.login.LoginActivity;

/**
 * Created by jiangyongxing on 2017/5/12.
 * 描述：
 */

public class LoginUtil {

    /**
     * 判断登录的状态
     *
     * @return true 已经登录
     * false  没有登陆
     */
    public static boolean isLogin() {
        return UserDao.getInstance().isUserLogin();
    }

    /**
     * 判断登录的状态
     *
     * @return true 已经登录
     * false  没有登陆
     */
    public static boolean isLogin(Context context) {
        if (!isLogin()) {
            LoginActivity.start(context);
            return false;
        }
        return true;
    }

    public static void logout(Context context) {
        if (isLogin()) {
            UserDao.getInstance().deleteUser();
            PushManager.getInstance().turnOffPush(context);
            FRSharedPreferences.setStringSet(CookieConstant.SP_NAME_COOKIES, CookieConstant.PREF_COOKIES, null);
            FRSharedPreferences.clearSharePreference(FRSharedPreferences.DEFALUT_NAME);
        }
    }
}